package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.exceptions.ClientExistsException;

public class BankService {
	
	public void addClient(Bank bank, Client client) throws ClientExistsException {
		int max = bank.getNumClients();
		for (int i = 0; i < max; i++) {
			if (bank.getClient(i).equals(client))
				throw new ClientExistsException("the client " + client.getClientSalutation() + " already exists");
		}
		bank.addClient(client);
	}
	
	public void printMaximumAmountToWithdraw(Bank bank) {
		int num = bank.getNumClients();
		Client client1;	
		Account account1;
		for (int i = 0; i < num; i++) {
			client1 = bank.getClient(i);
			account1 = client1.getAccount(0);
			System.out.println("Maximum amount to withdraw for client " + i + " is " + account1.maximumAmountToWithdraw());
		}
	}
	
	public void printBalance(Bank bank) {		
		int num = bank.getNumClients();
		Client client1;	
		Account account1;
		for (int i = 0; i < num; i++) {
			client1 = bank.getClient(i);
			account1 = client1.getAccount(0);
			System.out.println("Balance of client " + i + " is " + account1.getBalance());
			}
		}
}
